package com.lkd.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lkd.base.ResponseResult;
import com.lkd.domain.Role;
import com.lkd.domain.User;
import com.lkd.pageParam.UserPageParam;
import com.lkd.service.IRoleService;
import com.lkd.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.lkd.base.ResponseResult.success;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2025-02-12
 */
@RestController
@Api("用户相关接口")
@RequestMapping("/api/user-service")
public class UserController {
    @Autowired
    private IUserService userService;
    @Autowired
    private IRoleService roleService;
    @ApiOperation("查看区域详情")
    @GetMapping("/search")
    public ResponseResult<Page<User>> search(UserPageParam param){
        Page<User> page =  userService.search(param);
        return success(page);
    }
    @ApiOperation("角色列表")
    @GetMapping("/role")
    public ResponseResult<List<Role>> getRoleList(UserPageParam param){
        List<Role> list = roleService.list();
        return success(list);
    }
    @ApiOperation("新增人员")
    @PostMapping("/user")
    public ResponseResult add(@RequestBody User user){
        userService.save(user);
        return success();
    }
    @ApiOperation("修改人员")
    @PostMapping("/userId")
    public ResponseResult update(@PathVariable Long UserId,@RequestBody User user){
        userService.updateById(user);
        return success();
    }
    @ApiOperation("删除人员")
    @DeleteMapping("/{userId}")
    public ResponseResult remove(@PathVariable Long UserId){
        userService.removeById(UserId);
        return success();
    }
}
